package rad.framework.jsf;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;

import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.faces.Validator;
import org.jboss.seam.annotations.intercept.BypassInterceptors;

@Name("rad.framework.jsf.IdValidator")
@BypassInterceptors
@Validator
public class NaturalIdValidator implements javax.faces.validator.Validator {

	public void validate(FacesContext context, UIComponent cmp, Object value)
			throws ValidatorException {

		if (value == null) {
			return;
		}

		// Converter should have converted this to something other than
		// a String at this point
		if (value instanceof String) {
			FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR,
					"Invalid Selection.", null);
			throw new ValidatorException(msg);
		}
	}
}
